/********************************************************************************
 * Project Name		[JavaSE_Fundamentals]
 * File Name     	[TestComparable.java]
 * Creation Date 	[2015-01-01]
 * 
 * Copyright© ge.y.yang@gmail.com All Rights Reserved
 * 
 * Work hard, play harder, think big and keep fit
 ********************************************************************************/
package collections;

import java.util.TreeSet;

/**
 * 集合框架 - java.lang.Comparable
 * 
 * @author 不落的太阳(Sean Yang aka ShortPeace)
 * @version 1.0
 * @since jdk 1.8
 * 
 */
public class TestComparable implements Comparable<TestComparable> {

	private int id;
	private String name;

	@Override
	public int compareTo(TestComparable o) {
		// jdk 1.7 的新增方法
		return Integer.compare(this.id, o.id);
	}

	@Override
	public String toString() {
		return "TestComparable [id=" + id + ", name=" + name + "]";
	}

	public static void main(String[] args) {
		TestComparable tc1 = new TestComparable();
		tc1.id = 1;
		tc1.name = "Yang";

		TestComparable tc2 = new TestComparable();
		tc2.id = 2;
		tc2.name = "Sean";

		TreeSet<TestComparable> set = new TreeSet<>();
		set.add(tc1);
		set.add(tc2);

		System.out.println(set);
	}
}
